<?php

namespace app\admin\controller;

use think\Request;
use think\Controller;
use think\Db;

header('Access-Control-Allow-Origin: http://123.57.182.61:8086');
 header('Access-Control-Allow-Origin: *');
class Download extends Controller
{   
    public function download(){
       $param['idnumber'] =Request::instance()->param('idnumber');
        $a=Db::table('oa_admin_files')
            ->where('user_idnumber',$param['idnumber'])
            ->find();
        if($a){

        $b=$a['real_path'];
        $file_path="http://123.57.182.61:8086/php";
        $file_dir=$file_path.$b;
        $file_name=$a['file_name'];
        $data['file_dir']= $file_dir;
        $data['file_name']= $file_name; 
       /* $data['file_dir']= $file_dir; */
/*            Header ( "Content-type: application/octet-stream" );    
            Header ( "Accept-Ranges: bytes" );    
            Header ( "Accept-Length: " . filesize ( $file_dir  ) );    
            Header ( "Content-Disposition: attachment; filename=" . $file_name); */

            /*readfile($file_dir);*/
         return resultArray(['data'=>$data]);   
        }else{
            return resultArray(['error'=>'文件不存在']);
        }
    }  



    //导入个人信息模板
    public function DownloadTemplate()
    {
    $file_dir='http://123.57.182.61:8086/php/uploads/demo.xlsx';
    $file_name='demo.xlsx';
/*            Header ( "Content-type: application/octet-stream" );    
            Header ( "Accept-Ranges: bytes" );    
            Header ( "Accept-Length: ".filesize($file_dir) );    
            Header ( "Content-Disposition: attachment; filename=" . $file_name); */
    $data['file_dir']=$file_dir;
    $data['file_name']=$file_name;
    return resultArray(['data'=>$data]);
/*         $path_name='http://localhost/cultivate/php/uploads/demo.xlsx';
         ob_end_clean();
         $hfile = fopen($path_name, "rb") or die("Can not find file: $path_name\n");
         Header("Content-type: application/octet-stream");
         Header("Content-Transfer-Encoding: binary");
         Header("Accept-Ranges: bytes");
         Header("Content-Length: ".filesize($path_name));
         Header("Content-Disposition: attachment; filename=\ "$path_name\"");
         while (!feof($hfile)) {
 
            echo fread($hfile, 1024);
         }
         fclose($hfile);
         $data['path_name']=$path_name;
         return resultArray(['data'=>$data]);*/
    }  
    //导入专家信息模板
    public function DownloadExpert()
    {
    $file_dir='http://123.57.182.61:8086/php/uploads/expertDemo.xlsx';
    $file_name='expertDemo.xlsx';

    $data['file_dir']=$file_dir;
    $data['file_name']=$file_name;
    return resultArray(['data'=>$data]);

    } 

}
